<?php
require_once 'Models/Admin/Dao/AdminBaseDao.php';

class AdminSessionDao extends AdminBaseDao {
	private static $tableName = 'admin_session';
	
	public function add($fields) {
		if (!is_array($fields)) return 0;
		return $this->queryHelper()->insert(self::$tableName, $fields);
	}
	
	public function get($sessionId) {
		$sessionId = trim($sessionId);
		if ($sessionId == '') return null;

		return $this->queryHelper()->get(self::$tableName, null, 'session_id=?', array($sessionId));
	}
	
	public function delete($sessionId) {
		$sessionId = trim($sessionId);
		if ($sessionId == '') return 0;

		return $this->queryHelper()->delete(self::$tableName, 'session_id=?', array($sessionId));
	}
	
	public function deletesByExpire($timestamp) {
		$timestamp = intval($timestamp);

		return $this->queryHelper()->delete(self::$tableName, 'expire<=?', array($timestamp));
	}
	
	public function update($sessionId, $fields) {
		$sessionId = trim($sessionId);
		if ($sessionId == '') return 0;
		if (!is_array($fields) || !count($fields)) return 0;
		
		return $this->queryHelper()->update(self::$tableName, $fields, 'session_id=?', array($sessionId));
	}

}
